﻿using System;

namespace Tequila.Phone.Sharing
{
    /// <summary>
    /// Occurs when sharing service doesn't behaves successfully.
    /// </summary>
    public class ShareServiceException : Exception
    {
        /// <summary>
        /// Gets error <see cref="ShareServiceErrorType">type</see>.
        /// </summary>
        public ShareServiceErrorType ErrorType { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ShareServiceException" /> class.
        /// </summary>
        public ShareServiceException()
            : this(ShareServiceErrorType.Unexpected)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ShareServiceException" /> class with specified error type that describes the error.
        /// </summary>
        /// <param name="errorType">Error <see cref="ShareServiceErrorType">type</see>.</param>
        public ShareServiceException(ShareServiceErrorType errorType)
        {
            ErrorType = errorType;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ShareServiceException" /> class and a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException" /> parameter is not null, the current exception is raised in a catch block that handles the inner exception. </param>
        public ShareServiceException(Exception innerException)
            : this(ShareServiceErrorType.Unexpected, innerException)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ShareServiceException" /> class with specified error type that describes the error and a reference to the inner exception that is the cause of this exception.
        /// </summary>
        /// <param name="errorType">Error <see cref="ShareServiceErrorType">type</see>.</param>
        /// <param name="innerException">The exception that is the cause of the current exception. If the <paramref name="innerException" /> parameter is not null, the current exception is raised in a catch block that handles the inner exception. </param>
        public ShareServiceException(ShareServiceErrorType errorType, Exception innerException)
            : base(string.Empty, innerException)
        {
            ErrorType = errorType;
        }

        /// <summary>
        /// Gets a message that describes the current exception.
        /// </summary>
        /// <returns>
        /// The error message that explains the reason for the exception, or an empty string("").
        /// </returns>
        public override string Message
        {
            get { return Enum.GetName(typeof (ShareServiceErrorType), ErrorType); }
        }
    }
}
